//
//  QYGMineFetchCell.m
//  wawaji_ios
//
//  Created by 云+物娱 on 2017/12/8.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGMineFetchCell.h"

@interface QYGMineFetchCell()

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *accessoryLabel;
@property (nonatomic, strong) UIButton *pickBtn;
@property (nonatomic, strong) UIImageView *pickCompleteImg;

@end

@implementation QYGMineFetchCell

- (void)fetCellWithIconStr:(NSString *)iconStr nameStr:(NSString *)nameStr detailStr:(NSString *)detalStr fetchCellMode:(FetchCellMode)fetchCellMode accessoryStr:(NSString *)accessoryStr accessColor:(UIColor *)accessColor isPick:(BOOL)isPick{
    
    _iconStr = iconStr;
    _nameStr = nameStr;
    _detailStr = detalStr;
    _accessoryStr = accessoryStr;
    _fetchCellMode = fetchCellMode;
    _isPick = isPick;
    
    [self.iconView setImageURL:[NSURL URLWithString:iconStr]];
    self.nameLabel.text = nameStr;
    self.detailLabel.text = detalStr;
    self.accessoryLabel.text = accessoryStr;
    if(fetchCellMode == FetchCellModeRecord){
        self.pickCompleteImg.hidden = YES;
        self.pickBtn.hidden = YES;
        self.accessoryLabel.hidden = NO;
        self.accessoryLabel.textColor = accessColor;
        [self.accessoryLabel sizeToFit];
    }else if(fetchCellMode == FetchCellModeMineDoll){
        
        self.pickCompleteImg.hidden = !isPick;
        self.pickBtn.hidden = isPick;
        self.accessoryLabel.hidden = YES;
    }
    
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
}
- (void)setAccessoryStr:(NSString *)accessoryStr{
    
    _accessoryStr = accessoryStr;
    self.accessoryLabel.text = accessoryStr;
    [self.accessoryLabel sizeToFit];
}
- (void)setDetailStr:(NSString *)detailStr{
    
    _detailStr = detailStr;
    self.detailLabel.text = detailStr;
    [self.detailLabel sizeToFit];
}
- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.nameLabel.text = nameStr;
    [self.nameLabel sizeToFit];
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.layer.cornerRadius = 4;
        [self initUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame{
    
    frame.size.height  -= ScaleW(15);
    frame.origin.x = ScaleW(15);
    frame.size.width -= ScaleW(30);
    [super setFrame:frame];
}
- (void)initUI{
    
    [self addSubview:self.iconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
    [self addSubview:self.accessoryLabel];
    [self addSubview:self.pickBtn];
    [self addSubview:self.pickCompleteImg];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.iconView.x = ScaleW(15);
    self.iconView.y = 0.5 * (self.height - self.iconView.height);
    
    self.nameLabel.x = CGRectGetMaxX(self.iconView.frame) + ScaleW(15);
    self.nameLabel.y = self.iconView.y + ScaleW(4);
    
    self.detailLabel.x = self.nameLabel.x;
    self.detailLabel.y = CGRectGetMaxY(self.nameLabel.frame) + ScaleW(8);
    
    self.accessoryLabel.x = self.width - self.accessoryLabel.width - ScaleH(10);
    self.accessoryLabel.centerY = self.iconView.centerY;
    
    self.pickBtn.x = self.width - self.pickBtn.width - ScaleW(8);
    self.pickBtn.centerY = self.iconView.centerY;
    
    self.pickCompleteImg.x = self.width - self.pickCompleteImg.width;
    self.pickCompleteImg.y = 0;
    
    self.nameLabel.width = self.accessoryLabel.x - self.nameLabel.x - ScaleW(5);
}


#pragma mark lazy

- (UIImageView *)pickCompleteImg{
    if(!_pickCompleteImg){
        _pickCompleteImg = [[UIImageView alloc] init];
        _pickCompleteImg.size = CGSizeMake(ScaleW(57), ScaleW(60));
    }
    return _pickCompleteImg;
}
- (UIButton *)pickBtn{
    if(!_pickBtn){
        _pickBtn = [UIButton buttonWithTitle:@"点击领取" setTitleFont:ScaleFont(14)];
        _pickBtn.size = CGSizeMake(ScaleW(65), ScaleW(40));
        [_pickBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _pickBtn.backgroundColor = [UIColor cm_mainColor];
        _pickBtn.layer.cornerRadius = 4;
    }
    return _pickBtn;
}
- (UIImageView *)iconView{
    
    if(!_iconView){
        _iconView = [[UIImageView alloc] init];
        _iconView.size = CGSizeMake(ScaleW(40), ScaleW(40));
        _iconView.layer.cornerRadius = ScaleW(20);
        _iconView.layer.masksToBounds = YES;
        _iconView.backgroundColor = [UIColor cm_mainColor];
    }
    return _iconView;
}
- (UILabel *)accessoryLabel{
    
    if(!_accessoryLabel){
        _accessoryLabel = [UILabel labelWithText:@"" setFont:ScaleFont(14) setTextColor:[UIColor colorWithHex:@"EC6564"] setTextAlignment:NSTextAlignmentRight];
        _accessoryLabel.size = CGSizeMake(ScaleW(120), ScaleW(20));
        _accessoryLabel.numberOfLines = 1;
    }
    return _accessoryLabel;
}

- (UILabel *)detailLabel{
    
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"A3A3A3"] setTextAlignment :NSTextAlignmentLeft];
        _detailLabel.numberOfLines = 1;
    }
    return _detailLabel;
}
- (UILabel *)nameLabel {
    
    if(!_nameLabel){
        
        _nameLabel = [UILabel labelWithText:@"" setFont:ScaleFont(14) setTextColor:[UIColor colorWithHex:@"000000"] setTextAlignment :NSTextAlignmentLeft];
        _nameLabel.numberOfLines = 1;
    }
    return _nameLabel;
}

@end
